package com.traffic.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.traffic.domain.PerAccessControlCards;
import com.traffic.service.IPerAccessControlCardsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 门卡配置Controller
 * 
 * @author 郭世纪
 * @date 2024-12-08
 */
@RestController
@RequestMapping("/cards")
public class PerAccessControlCardsController extends BaseController
{
    @Autowired
    private IPerAccessControlCardsService perAccessControlCardsService;

    /**
     * 查询门卡配置列表
     */
    @RequiresPermissions("personnel:cards:list")
    @GetMapping("/list")
    public TableDataInfo list(PerAccessControlCards perAccessControlCards)
    {
        startPage();
        List<PerAccessControlCards> list = perAccessControlCardsService.selectPerAccessControlCardsList(perAccessControlCards);
        return getDataTable(list);
    }

    /**
     * 导出门卡配置列表
     */
    @RequiresPermissions("personnel:cards:export")
    @Log(title = "门卡配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PerAccessControlCards perAccessControlCards)
    {
        List<PerAccessControlCards> list = perAccessControlCardsService.selectPerAccessControlCardsList(perAccessControlCards);
        ExcelUtil<PerAccessControlCards> util = new ExcelUtil<PerAccessControlCards>(PerAccessControlCards.class);
        util.exportExcel(response, list, "门卡配置数据");
    }

    /**
     * 获取门卡配置详细信息
     */
    @RequiresPermissions("personnel:cards:query")
    @GetMapping(value = "/{cardId}")
    public AjaxResult getInfo(@PathVariable("cardId") Long cardId)
    {
        return success(perAccessControlCardsService.selectPerAccessControlCardsByCardId(cardId));
    }

    /**
     * 新增门卡配置
     */
    @RequiresPermissions("personnel:cards:add")
    @Log(title = "门卡配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PerAccessControlCards perAccessControlCards)
    {
        return toAjax(perAccessControlCardsService.insertPerAccessControlCards(perAccessControlCards));
    }

    /**
     * 修改门卡配置
     */
    @RequiresPermissions("personnel:cards:edit")
    @Log(title = "门卡配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PerAccessControlCards perAccessControlCards)
    {
        return toAjax(perAccessControlCardsService.updatePerAccessControlCards(perAccessControlCards));
    }

    /**
     * 删除门卡配置
     */
    @RequiresPermissions("personnel:cards:remove")
    @Log(title = "门卡配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cardIds}")
    public AjaxResult remove(@PathVariable Long[] cardIds)
    {
        return toAjax(perAccessControlCardsService.deletePerAccessControlCardsByCardIds(cardIds));
    }
}
